package com.lyz.dataStructure.考研上机编程题;/**
 * @Author:759057893@qq.com Lyz
 * @Date: ${Date} 21:32
 * @Description:
 **/

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

/**
 *@Author:759057893@qq.com Lyz
 *@Date: 2019/9/17 21:32
 *@Description:
 **/
class Stu{
    int id;
    int score;
}
public class 成绩排序 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()){
            int  n = Integer.parseInt(sc.nextLine());
            Stu[] stu = new Stu[n];
            for(int i =0;i<n;i++){
                String[] str = sc.nextLine().split(" ");
                stu[i]=new Stu();
                stu[i].id = Integer.parseInt(str[0]);
                stu[i].score = Integer.parseInt(str[1]);
            }
            Comp cmp=new Comp();
            Arrays.sort(stu,cmp);
            for(int i =0;i<n;i++){
                System.out.println(stu[i].id+" "+stu[i].score);
            }
        }
    }
}

class Comp implements Comparator<Stu> {

    @Override
    public int compare(Stu o1, Stu o2) {
       if(o1.score==o2.score){
            return o1.id-o2.id;
       }
       return o1.score-o2.score;
    }
}


/*
3
1 90
2 89
3 88
   while (sc.hasNext()){
            int m = Integer.parseInt(sc.nextLine());
            int[] num = new int[m];
            for(int i =0;i<m;i++){
                String[] str = sc.nextLine().split(" ");
                num[i] = Integer.parseInt(str[0]);
                num[i] = Integer.parseInt(str[1]);
            }
        }
 */